using System;
using System.Configuration;

namespace DemoPress.BlogServices.Configuration
{
    internal class DemoPressDataSectionHandler: IConfigurationSectionHandler
    {
        private string _assembly;
        private string _dataService;

        public string DataService
        {
            get { return _dataService; }
        }

        public string Assembly
        {
            get { return _assembly; }
        }

        #region IConfigurationSectionHandler Members

        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            if (configContext == null)
            {
                throw new ArgumentNullException("configContext", "The configContext object provided is null");
            }
            if (section == null)
            {
                throw new ArgumentNullException("section", "The RewriteModule section Node is null and can not be processed.");
            }
            if (section.SelectSingleNode("assembly") == null)
            {
                throw new ArgumentException("The Assembly section Node has no rewriteOn attribute.", "section");
            }
            if (section.SelectSingleNode("dataService") == null)
            {
                throw new ArgumentException("The DataService section Node has no rewriteOn attribute.", "section");
            }
            _assembly = section.SelectSingleNode("assembly").Attributes["value"].Value;
            _dataService = section.SelectSingleNode("dataService").Attributes["value"].Value;
            return this;
        }

        #endregion
    }
}
